package ru.papergames.model.binsocket.packets.response
{
	import ru.papergames.model.binsocket.data.ExtByteArray;
	import ru.papergames.model.binsocket.packets.SocketResponse;

	public class SystemMessageResponse extends SocketResponse
	{		
		public static const BATTLE_START_TIME:String = 'SystemMessageResponse_BATTLE_START_TIME';
		public static const NOT_YOUR_TURN:String = 'SystemMessageResponse_NOT_YOUR_TURN';
		public static const PLAYER_FINISHED_TURN:String = 'SystemMessageResponse_PLAYER_FINISHED_TURN';
		public static const PLAYER_TURN_STARTED:String = 'SystemMessageResponse_PLAYER_TURN_STARTED';
		public static const NO_ACTION_POINTS:String = 'SystemMessageResponse_NO_ACTION_POINTS';
		public static const TURN_TIME_FINISHED_WAIT_FOR_NOTIFICATION:String = 'SystemMessageResponse_TURN_TIME_FINISHED_WAIT_FOR_NOTIFICATION';
		public static const LAST_ACTION_STILL_PROCEEDS:String = 'SystemMessageResponse_LAST_ACTION_STILL_PROCEEDS';
		public static const NO_ENEMY_AT_CELL:String = 'SystemMessageResponse_NO_ENEMY_AT_CELL';
		public static const BAD_DISTANCE:String = 'SystemMessageResponse_BAD_DISTANCE';
		
		private static const NOTIFICATIONS_MAP:Object = { 	
															id_34 : LAST_ACTION_STILL_PROCEEDS,
															id_35 : TURN_TIME_FINISHED_WAIT_FOR_NOTIFICATION,
															id_36 : NOT_YOUR_TURN, 
															
															id_39 : NO_ACTION_POINTS,
															id_41 : BAD_DISTANCE};
														

		private static const TYPE_NUMBER:uint 	= 1;

		
		public var messageId:int;
		public var params:Array = [];
		
		public function SystemMessageResponse(bytes:ExtByteArray)
		{
			super(bytes);
		}
		
		override public function getNotification():String {
			return NOTIFICATIONS_MAP['id_' + messageId];
		}
		
		override protected function decode():void {
			messageId = binaryData.readInt();
			
			var paramsCount:uint = binaryData.readInt();
			
			while (binaryData.bytesAvailable > 0 && paramsCount-- > 0) {
				//there's some additional data
				var paramType:uint = binaryData.readInt();
				
				switch(paramType) {
					case TYPE_NUMBER:
						params.push(binaryData.readInt());
						break;
						
				}
			}
		}
	}
}